package engine

type ParserFunc func(
	contents []byte,url string) ParseResult

type Parser interface {
	Parse(contents []byte,url string) ParseResult
	Serialized()(name string,args interface{})
}

type Request struct {
	UrL string
	Parser Parser
}


type Item struct {
	Url string
	Type string
	Id string
	Payload interface{}
}

type ParseResult struct {
	Requests []Request
	Items    []Item
}

type FuncParser struct {
	parser ParserFunc
	name string
}

func (f *FuncParser) Parse(contents []byte, url string) ParseResult {
	return f.parser(contents,url)
}

func (f *FuncParser) Serialized() (name string, args interface{}) {
	return f.name,nil
}

func NewParserFunc(p ParserFunc,name string) *FuncParser  {
	return &FuncParser{
		parser:p,
		name:name,
	}
}

type NilParser struct {}

func (f NilParser) Parse(_ []byte, _ string) ParseResult {
	 return ParseResult{}
}

func (f NilParser) Serialized() (name string, args interface{}) {
	return "NilParser",""
}


